<template>
  <view class="uni-goods-nav">
    <!-- 底部占位 -->
    <view class="uni-tab__seat" />
    <view class="uni-tab__cart-box flex">
      <view class="flex uni-tab__cart-sub-box">
        <view
          v-for="(item, index) in options"
          :key="index"
          class="flex uni-tab__cart-button-left"
          @click="optionClick(index, item)"
        >
          <view class="uni-tab__icon">
            <image class="image" :src="item.icon" mode="widthFix" />
          </view>
          <text class="uni-tab__text">{{ item.text }}</text>
          <view v-if="item.info" class="flex uni-tab__dot-box">
            <text
              :class="{ 'uni-tab__dots': item.info > 9 }"
              class="uni-tab__dot"
            >{{ item.info > 9 ? '9+' : item.info }}</text>
          </view>
        </view>
      </view>
      <view :class="{ 'uni-tab__right': fill }" class="flex uni-tab__cart-sub-box">
        <view
          v-for="(item, index) in buttonGroup"
          :key="index"
          :style="{ backgroundColor: item.backgroundColor }"
          class="flex uni-tab__cart-button-right uni-tab__color"
          @click="buttonClick(index, item)"
        >
          <text class="uni-tab__button-text">{{ item.text }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    options: {
      type: Array,
      default: () => [
        { icon: '/static/icon/kefu.png', text: '客服', info: 0 },
        { icon: '/static/icon/dianpu.png', text: '店铺', info: 0 },
        { icon: '/static/icon/cart.png', text: '购物车', info: 0 }
      ]
    },
    buttonGroup: {
      type: Array,
      default: () => [
        { text: '加入购物车', backgroundColor: '#ff0000', color: '#fff' },
        { text: '立即购买', backgroundColor: '#ffa200', color: '#fff' }
      ]
    },
    fill: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    optionClick(index, item) {
      this.$emit('optionClick', { index, item });
    },
    buttonClick(index, item) {
      this.$emit('buttonClick', { index, item });
    }
  }
};
</script>

<style scoped>
.uni-goods-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
}
.uni-tab__seat {
  height: 1px;
  background-color: #eee;
}
.uni-tab__cart-box {
  background-color: #fff;
  padding: 10px;
}
.uni-tab__cart-sub-box {
  align-items: center;
}
.uni-tab__cart-button-left {
  margin-right: 20px;
}
.uni-tab__icon .image {
  width: 24px;
  height: 24px;
}
.uni-tab__text {
  margin-left: 5px;
  font-size: 14px;
}
.uni-tab__dot-box {
  margin-left: 5px;
}
.uni-tab__dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  background-color: #ff0000;
  color: #fff;
  font-size: 12px;
}
.uni-tab__dots {
  font-size: 10px;
}
.uni-tab__right {
  flex: 1;
  justify-content: flex-end;
}
.uni-tab__cart-button-right {
  padding: 8px 15px;
  border-radius: 4px;
  color: #fff;
  margin-left: 10px;
}
.uni-tab__button-text {
  font-size: 14px;
}
</style>